<template>
  <div>
    <div class="title">
      <el-menu
        :default-active="activeIndex"
        class="el-menu-demo"
        mode="horizontal"
        @select="stateBtn"
      >
        <el-menu-item index="0">审核中</el-menu-item>
        <el-menu-item index="9">审核记录</el-menu-item>
      </el-menu>
      <div>
        <!-- <el-button type="primary"><i class="el-icon-download"></i>导出</el-button> -->
        <el-button icon="el-icon-refresh" @click="refresh"></el-button>
      </div>
    </div>
    <div class="container">
     
      <div class="tableBox">
        <el-table
          ref="multipleTable"
          :data="merchantarr"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
          stripe
          :header-cell-style="tableHeaderColor"
          v-loading="loading"
        >
          <el-table-column type="index" align="center" label="序号"></el-table-column>
          <el-table-column type="selection"></el-table-column>
          <el-table-column prop="createTime" align="center" label="提交时间"></el-table-column>
          <el-table-column prop="tradeNo" align="center" label="订单号"></el-table-column>
          <el-table-column prop="auditName" align="center" label="处理人"></el-table-column>
          <el-table-column prop="applyName" align="center" label="申请人名称"></el-table-column>
        
          <el-table-column align="center" label="审核状态">
            <template slot-scope="scope">
              <div v-show='scope.row.auditStatus == 0'>待审核</div>
              <!-- <div v-else-if='scope.row.auditStatus == 2'>审核驳回</div> -->
              <div v-show='scope.row.auditStatus == 1' class='green'>审核通过</div>
               <el-popover
                placement="top-start"
                title="驳回原因"
                width="200"
                trigger="hover"
                :content="scope.row.refundReason">
                <el-button type="text" v-show="scope.row.auditStatus == 2" slot="reference">审核驳回</el-button>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column fixed="right" align="center" label="操作" width="120">
            <template slot-scope="scope">
              <!-- <div v-if="scope.row.status == 1 && (userinfo.rolesId == 1 || userinfo.rolesId == 8)"> -->
                <el-button v-if="scope.row.auditStatus == 0 && userinfo.rolesId == 9" type="text" size="small" @click="joinmerchantsinfo(scope.row)">审核</el-button>
              <!-- </div> -->
              <!-- <el-button type="text" size="small" @click="addmerdetails(scope.row)">详情</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination">
          <el-pagination
            @current-change="handleCurrentChange"
            @size-change="sizechange"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </div>
      <br>
      <br>
    </div>
    <!-- 审核 -->
    <el-dialog v-dialogDrag title="审核" :visible.sync="visible" width="45%" :close-on-click-modal="false">
        <el-form  status-icon ref="refund" label-width="110px" class="demo-dynamic">
          <el-form-item label="退款原因">
              <el-radio-group v-model="refund.type">
                <el-radio :label="1">同意</el-radio>
                <el-radio :label="2">驳回</el-radio>
              </el-radio-group>
          </el-form-item>
           <el-form-item label="退款原因">
            <el-input type="textarea" v-model.trim="refund.refundReason" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="visible = false">取消</el-button>
          <el-button type="primary" @click="refundok()">确定</el-button>
        </span>
      </el-dialog>
  </div>
</template>

<script>
import { applylist,auditpass,auditreject } from "@/api/api";
export default {
  // name: "baseform",
  data: function() {
    return {
      activeIndex: '0',
      cur_page: 1,
      cur_size: 10,
      BDarr:[],
      multipleSelection: [],
      merchantarr: [],
      total:10,
      userinfo:{},
      conditions: {
        merchantsstate: 0,
      },
      oeminfo:'',
      oemFlag:'',
      visible: false,
      refund:{
        type:1,
        refundReason:''
      },
      loading:true,
    };
  },
  created() {
    this.userinfo = JSON.parse(sessionStorage.getItem("userInfo"));
    this.merchantlist();

   
    // 判断是否是oem
    this.oeminfo = JSON.parse(sessionStorage.getItem('oeminfo'))
    this.oemFlag = sessionStorage.getItem('oemFlag')

  },
  mounted() {},
  methods: {
    //修改thead 背景色
     tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return 'background-color: #F0F0F0;font-weight: 500;'
      }
    },
   
    // 分页导航
    handleCurrentChange(val) {
      this.cur_page = val;
      this.merchantlist();
      this.$nextTick(() => {
        document.querySelectorAll(".content")[0].scrollTop = "0";
      });
    },
    // 分页数量
    sizechange(val) {
      this.cur_size = val;
      this.merchantlist();

      this.$nextTick(() => {
        document.querySelectorAll(".content")[0].scrollTop = "0";
      });
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    joinmerchantsinfo(val) {
     this.visible = true
     this.refund.type = 1
     this.refund.refundReason = ''
     this.refund.id = val.id
    },
     // 商户列表
    merchantlist(level) {
      let sosolist = {};
      applylist({
         page: this.cur_page,
        size: this.cur_size,
        auditStatus:this.conditions.merchantsstate
      }).then(res => {
        // console.log(res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          this.merchantarr = res.data.rows;
          this.combined = res.data.total;
          this.loading = false;
          this.total = res.data.total
        }
      });
    },
    // 刷新
    refresh() {
      // location.reload()
      this.$router.replace({
        path: "/refresh",
        query: {
          t: Date.now()
        }
      });
    },
    // 状态btn
    stateBtn(val){
      console.log(val)
      this.conditions.merchantsstate = val
      this.cur_page = 1;
      this.merchantlist()
    },
  
    refundok(){
      if(this.refund.type == 1){
        auditpass({
          id: this.refund.id
        }).then(res =>{
          if(res.code == 200){
             this.$message({
              message:'退款成功',
              type:'success'
            })
            this.visible = false
            this.merchantlist()
          }else{
             this.$message.error(res.message);
          }
            
        })
      }else if(this.refund.type == 2){
        auditreject({
          id: this.refund.id,
          refundReason:this.refund.refundReason
        }).then(res =>{
          if(res.code == 200){
             this.$message({
              message:'已驳回',
              type:'success'
            })
            this.visible = false
            this.merchantlist()
          }else{
             this.$message.error(res.message);
          }
           
        })
      }
    }
  }
};
</script>
<style scoped lang="less">
.title {
  background: #fff;
  padding: 10px 10px;
  font-size: 18px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}
.name {
  width: 25%;
}
.screeningBox {
  width: 100%;
  display: flex;
}
.leftBox,
.rightBox {
  width: 50%;
  padding: 0 15px;
  box-sizing: border-box;
}
.leftBox > .leftitem {
  margin-bottom: 15px;
}
.rightBox > .rightitem {
  margin-bottom: 15px;
}
.merchants {
  width: 50%;
}
.statistical {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #374459;
  color: #fff;
  padding: 12px;
  box-sizing: border-box;
}
.statistical > .statisticalitem {
  width: 50%;
  text-align: center;
  line-height: 200%;
}
.tableBox {
  margin-top: 20px;
}

.red {
  color: #f9607d;
}

.my-autocomplete {
  li {
    line-height: normal;
    padding: 7px;

    .name {
      text-overflow: ellipsis;
      overflow: hidden;
    }
    .addr {
      font-size: 12px;
      color: #b4b4b4;
    }

    .highlighted .addr {
      color: #ddd;
    }
  }
}
.green{
  color:green;
}
</style>